<template>
  <a-config-provider :locale="zhCN">
  <div>
    <!-- 头部 -->
    <Header/>
    <!-- 身体 -->
    <div class="box">
      <ConfigProvider :locale="locale">
        <router-view v-if="isRouterAlive" />
      </ConfigProvider>
    </div>
    <!-- 尾部 -->
    <Footer/>
<!--    <Loading v-show="onLoading"></Loading>-->
  </div>
  </a-config-provider>
</template>
<script>
import Header from '@/components/frame/Header.vue'
import Footer from '@/components/frame/Footer.vue'
import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN'
import store from '@/store/index'
import { ConfigProvider } from 'ant-design-vue'
import {mapGetters} from 'vuex'
export default {
  components: { Header, Footer, ConfigProvider },
  provide(){
    return {
      reload:this.reload
    }
  },
  data () {
    return {
      zhCN,
      locale: zhCN,
       // 怕版权影响换张图片
      imgUrl: require("@/assets/image/pagint.png"),
      onLoading:false,
      isRouterAlive:true
    }
  },
  computed: {
      ...mapGetters([
          'showonLoading'
      ])
  },
  watch: {
      showonLoading(newVal) {
          this.onLoading = newVal;
      },
  },
  methods:{
    reload(){
      this.isRouterAlive = false
      this.$nextTick(function (){
        this.isRouterAlive = true
      })
    }
  },
  // 生命周期-实例创建完成后调用
  created () {
    // js 监听页面刷新并存储vuex数据
    window.addEventListener("beforeunload", () => {
      localStorage.setItem("stateInfo", JSON.stringify(this.$store.state));
    });
    // 判断还原vuex的数据
    if (localStorage.getItem("stateInfo")) {
      this.$store.replaceState(
        Object.assign(
          {},
          this.$store.state,
          JSON.parse(localStorage.getItem("stateInfo"))
        )
      );
    }
    // 删除历史缓存vuex数据
    localStorage.removeItem("stateInfo");
  },
  mounted(){
    if(localStorage.rememberPassword == 'true'){
      if(!this.$store.state.token){
        this.$ajax({
          url:"/authority/user/app/oneclick/login",
          method:"post",
          params:{
            userName:localStorage.userName,
            // password:localStorage.password
          }
        }).then((res)=>{
          if(res.code == 200){
            this.$message.success("登录成功")
            this.$store.commit('changelocalImgFlag',res.data.localImgFlag);
            this.$store.commit('changenickName',res.data.userinfo.nickName);
            this.$store.commit('changeresumeNo',res.data.userinfo.resumeNo);
            this.$store.commit('changepwdFlag',res.data.pwdFlag);
            this.$store.commit('changeroleType',res.data.userinfo.roleType);
            this.$store.commit('changemobile',res.data.userName);
            this.$store.commit('changepicture',res.data.userinfo.picture);
            this.$store.commit('changeToken',res.data.token);
            this.$store.commit('changeuserName',res.data.userName);
            // this.$emit('closeModel');
            // this.reload()
            this.$router.go(0)
          }else{
            this.loading = false;
            // this.$message.error(res.msg);
            this.messageerror = res.msg;
            localStorage.setItem('rememberPassword',false);
            localStorage.setItem('userName','');
            localStorage.setItem('password','');
          }
        })
      }else{
        // console.log('mei')
      }
    }
    // this.onLoading = store.state.onLoading
  }
}
</script>

<style scoped lang="less">
.box{
  min-height: calc(100vh - 284px);
}
</style>
